//
//  ZipTool.swift
//  ZipTools
//
//  Created by 齐庆斌 on 2018/4/12.
//  Copyright © 2018年 齐庆斌. All rights reserved.
//

import UIKit
import SSZipArchive

class ZipTool: NSObject {
    
    var delegate: SSZipArchiveDelegate?
    
    // 压缩文件
    class func zipFiles(files: [String], path: String) -> Bool {
        return  SSZipArchive.createZipFile(atPath: path, withFilesAtPaths:files)
    }
    
    // 解压文件
    class func archiveZip(sourcePath: String, destinationPath: String) -> Bool {
        return SSZipArchive.unzipFile(atPath: sourcePath, toDestination: destinationPath, delegate: nil)
    }
    
    // 为压缩文件加密码
    class func zipFilesWithpassword(files: [String], path: String, password: String) -> Bool {
        return SSZipArchive.createZipFile(atPath: path, withFilesAtPaths: files, withPassword: password)
    }
    
}

extension ZipTool: SSZipArchiveDelegate {
    func zipArchiveWillUnzipArchive(atPath path: String, zipInfo: unz_global_info) {
        print("start unzip")
    }
    
    func zipArchiveDidUnzipFile(at fileIndex: Int, totalFiles: Int, archivePath: String, fileInfo: unz_file_info) {
        print("end")
    }
}
